import {_decorator, Component, Sprite, SpriteFrame, UITransform} from 'cc';
import {TILE_TYPE_ENUM} from "../../Enums";

const { ccclass, property } = _decorator;

export const TILE_WIDTH = 55;
export const TILE_HEIGHT = 55;

@ccclass('TileManager')
export class TileManager extends Component {
    type: TILE_TYPE_ENUM;
    movable: boolean;
    turnable: boolean;

    init(type: TILE_TYPE_ENUM, spriteFrame: SpriteFrame, i:number, j:number) {
        const sprite = this.node.addComponent(Sprite);
        sprite.spriteFrame = spriteFrame;

        this.type = type;
        if(type === TILE_TYPE_ENUM.FLOOR) {
            this.movable = true;
            this.turnable = true;
        } else if(type === TILE_TYPE_ENUM.CLIFF_LEFT || type === TILE_TYPE_ENUM.CLIFF_RIGHT || type === TILE_TYPE_ENUM.CLIFF_CENTER) {
            this.movable = false;
            this.turnable = true;
        } else {
            this.movable = false;
            this.turnable = false;
        }

        const uiTransform = this.getComponent(UITransform);
        uiTransform.setContentSize(TILE_WIDTH, TILE_HEIGHT);

        this.node.setPosition(i * TILE_WIDTH, j * TILE_HEIGHT * -1);
    }
}

